package golist

import (
	"container/list"
	"encoding/json"
)


type List struct {
	*list.List
}

func New() *List {
	return &List{list.New()}
}


func (this *List) MarshalJSON() ([]byte, error) {
	var result = make([]interface{}, 0)
	for e := this.Front(); e != nil; e = e.Next() {
		result = append(result, e.Value)
	}
	return json.Marshal(result)

}

func (this *List) UnmarshalJSON(data []byte) (err error) {

	//var result = make([]interface{}, 0)
	var result = this.Results()
	if err = json.Unmarshal(data, &result); err != nil {
		return err
	}
	for _, val := range result{
		this.PushBack(val)
	}
	return nil

}

func (this *List) Results() []interface{} {
	results:= make([]interface{},0)
	return results
}

